// pages/qiandao/course_detail/course_detail.js

import {
    baseUrl,
    isHaveToken,
    isLogin,
    javaUrl
} from "../../../utils/util";
Page({

    /**
     * 页面的初始数据
     */
    data: {
        course:{},
        class_id:"",
        course_id:"",
        CourseStatusList:"",
        class_img:"",
        class_name:"",
        class_teacher:""
    },
    getCourseStatus(){
        var that=this
        console.log("getCourseStatus",`${javaUrl}/xxt/login/getCourseStatus?phone=${that.data.phone}&pwd=${that.data.pwd}`)
        wx.request({
          url: `${javaUrl}/xxt/login/getCourseStatus?phone=${that.data.phone}&pwd=${that.data.pwd}`,
          method:'POST',
          data:{
              class_id:that.data.class_id,
              course_id:that.data.course_id
          },
          success(res){
              console.log("res",res)
              that.setData({
                CourseStatusList:res.data.data.CourseStatusList
              })
          }
        })

    },
    gotoresult(e){
        console.log("gotoresult",e)
        wx.navigateTo({
          url: `../course_result/course_result?class_img=${this.data.class_img}&class_name=${this.data.class_name}&activeid=${e.currentTarget.dataset.item.activeid}&status=${e.currentTarget.dataset.item.status}&type=${e.currentTarget.dataset.item.type}&class_id=${this.data.class_id}&course_id=${this.data.course_id}`,
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        var that = this
        if(isLogin()){
            if(that.data.CourseStatusList.length==0){
                wx.showToast({
                  title: '加载中',
                  duration: 1000,
                  icon: 'loading',
                  success: (res) => {},
                  fail: (res) => {},
                  complete: (res) => {},
                })
            }
            console.log('isLogin')
            that.setData({
                class_id:options.class_id,
                course_id:options.course_id,
                class_img:options.class_img,
                class_name:options.class_name,
                class_teacher:options.class_teacher,
                pwd:wx.getStorageSync('pwd'),
                phone:wx.getStorageSync('phone')
            })
            that.getCourseStatus()
        }else{
            wx.navigateTo({
              url: '/pages/xuexitong/my/my',
            })
        }

    },


    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})